package genetica.cromosomas.factorias;

import genetica.cromosomas.Cromosoma;
import genetica.cromosomas.CromosomaFuncionConN;
import genetica.cromosomas.evaluadores.evaluadorFuncionD;

import java.util.ArrayList;
import java.util.Random;

public class factoriaFuncionD extends FactoriaFuncion {
	private int n;
	public factoriaFuncionD( double precision, int n){
		super(precision);
		this.n = n;
	}
	@Override
	public Cromosoma crea() {
		Random r = new Random();
		ArrayList<Double>xmin = new ArrayList<Double>();
		ArrayList<Double>xmax = new ArrayList<Double>();
		for (int i = 0; i < this.n; i++) {
			xmin.add(0.0);
			xmax.add(100.0);
		}
		Cromosoma c = new CromosomaFuncionConN(xmin,xmax,precision,r, new evaluadorFuncionD(this.n),this.n);
		return c;
	}

	@Override
	public Cromosoma copia(Cromosoma original) {
		if (original instanceof CromosomaFuncionConN)
			return new CromosomaFuncionConN((CromosomaFuncionConN)original);
		else
			return null;
	}
	
	public int getN(){
		return this.n;
	}
	
	public void setN(int n){
		this.n = n;
	}
	
	@Override
	public String toString(){
		return "f(x) = (i=1..n)∑−xi·sen( xi ) : xi ∈ [0,100]";
	}

}
